<template>
  <div>
    <div class="row-header">
      <el-form :model="form" :rules="formRules" :inline="true" label-width="150px">
        <el-form-item label="imsi" prop="imsi">
          <el-input size="small" v-model.trim="form.imsi" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="iccid" prop="iccid">
          <el-input size="small" v-model.trim="form.iccid" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="处理状态" prop="dictStatus">
          <el-select size="small" v-model="form.dictStatus" placeholder="处理状态" style="width: 300px;" clearable>
            <el-option v-for="state in form.dictStatusSelect" :key="state.value" :label="state.label"
                       :value="state.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="去更改状态" prop="ditcToStatus">
          <el-select size="small" v-model="form.ditcToStatus" placeholder="处理状态" style="width: 300px;" clearable>
            <el-option v-for="state in form.ditcToStatusSelect" :key="state.value" :label="state.label"
                       :value="state.value"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="row-form-btn">
        <el-button size="small" type="shenda" icon="el-icon-search" @click="currentPage = 1 ; initData()">
          查询
        </el-button>
      </div>
    </div>
    <div class="split-line"></div>
    <div class="row-main">
      <el-table :header-cell-style="{ 'background':$store.state.app.tableBgColor,'color':'#606266' }" :data="tableData"
                tooltip-effect="dark" class="row-main-table" @selection-change="handleSelectionChange"
                v-loading.fullscreen="tableLoading" element-loading-text="拼命加载中"
                element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)">
        <el-table-column type="selection" align="center"></el-table-column>
        <el-table-column prop="imsi" label="imsi" align="center"></el-table-column>
        <el-table-column prop="ditcToStatus" label="去更改状态" align="center"></el-table-column>
        <el-table-column prop="updateTime" label="更新时间" align="center"></el-table-column>
        <el-table-column prop="dictRequestStatusName" label="处理状态" align="center"></el-table-column>
        <el-table-column prop="loginId" label="操作者" align="center"></el-table-column>
        <el-table-column prop="insertTime" label="创建时间" align="center"></el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" class="row-main-pager"
                     :current-page.sync="currentPage" :page-size="pageSize" layout="total,sizes,prev, pager, next, jumper"
                     :page-sizes="[10,20,50,100]" :total="total" background></el-pagination>

    </div>
  </div>
</template>

<script>
import {cardStatusChange} from '@/api/getData'

export default {
  name: 'StatusChange',
  data() {
    const validateCardId = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('cardId不能超过50位'))
      } else {
        callback()
      }
    }
    const validateImsi = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('imsi不能超过50位'))
      } else {
        callback()
      }
    }
    const validateIccid = (rule, value, callback) => {
      if (value.length > 50) {
        callback(new Error('iccid不能超过50位'))
      } else {
        callback()
      }
    }
    return {
      form: {
        cardId: '',
        imsi: '',
        iccid: '',
        ditcToStatus: '',
        ditcToStatusSelect: [
          {
            value: 'ACTIVATE',
            label: '已激活'
          },
          {
            value: 'DEACTIVATE',
            label: '去激活'
          },
          {
            value: 'PAUSE',
            label: '停机'
          },
          {
            value: 'TERMINATE',
            label: '拆机'
          },
          {
            value: 'REACTIVATE',
            label: '重新激活'
          },
          {
            value: 'TEST_READY',
            label: '可测试'
          },
          {
            value: 'RETIRED',
            label: '已失效'
          },
          {
            value: 'INVENTORY',
            label: '库存'
          }
        ],
        dictStatus: '',
        dictStatusSelect: [
          {
            value: 'TASK_COMPLETED',
            label: '完成'
          },
          {
            value: 'TASK_PENDING',
            label: '进行中'
          },
          {
            value: 'TASK_FAIL',
            label: '任务失败'
          }
        ]
      },
      formRules: {
        cardId: [{validator: validateCardId, trigger: 'blur'}],
        imsi: [{validator: validateImsi, trigger: 'blur'}],
        iccid: [{validator: validateIccid, trigger: 'blur'}]
      },
      maxPage: 1,
      tableData: [],
      pageSize: 10,
      currentPage: 1,
      total: 0,
      tableLoading: false,
      value: false,
      cardId: '',
      imsi: '',
      iccid: '',
      updateTime: '',
      dictRequestStatus: '',
      dictRequestStatusName: '',
      loginId: '',
      insertTime: '',
      dictOperatorName: '',
      dictOperatorNameSelect: [
        {
          value: 'TELECOM',
          label: '电信'
        },
        {
          value: 'MOBILE',
          label: '移动'
        },
        {
          value: 'UNICOM',
          label: '联通'
        }
      ]
    }
  },
  created() {
    this.initData()
  },
  methods: {
    async initData() {
      const returnData = await cardStatusChange({
          cardId: this.form.cardId,
          imsi: this.form.imsi,
          iccid: this.form.iccid,
          dictStatus: this.form.dictStatus,
          ditcToStatus: this.form.ditcToStatus,
          page: {
            current: this.currentPage + '',
            size: this.pageSize + '',
            ascs: this.ascs,
            descs: this.descs
          }
        },
        {
          obj: this,
          key: 'tableLoading'
        })
      this.tableData = [];
      this.total = 0;
      //console.log(returnData)
      if (returnData._result) {
        this.maxPage = Math.ceil(returnData.data.total / this.pageSize) // 分页的最大页数
        returnData.data.records.map(item => {
          const obj = {}
          obj.cardId = item.cardId // cardId
          obj.ditcToStatus = item.ditcToStatus // 去更改状态
          if (item.ditcToStatus === 'DEACTIVATE') {
            obj.ditcToStatus = '待激活'
          }
          if (item.ditcToStatus === 'ACTIVATE') {
            obj.ditcToStatus = '已激活'
          }
          obj.updateTime = item.updateTime // 更新时间
          obj.dictRequestStatus = item.dictRequestStatus // 处理状态
          obj.dictRequestStatusName = item.dictRequestStatusName // 处理状态
          obj.loginId = item.loginId // 操作者
          obj.insertTime = item.insertTime // 创建时间
          obj.imsi = item.imsi // imsi
          this.tableData.push(obj)
        })
        this.total = returnData.data.total;
        this.tableLoading = false
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.initData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.initData();
    },
  }
}
</script>

<style scoped lang="scss">

.examine /deep/ .el-dialog__body {
  text-align: center;
  font-size: 14px;
  font-family: 微软雅黑;
  line-height: 40px;
  color: #606266;
  font-weight: 700;
}

.el-popper[x-placement^=bottom] {
  margin-right: -25px;
  box-shadow: 0px 0px 10px #888888;
  margin-left: 6px;

  .operation {
    border: 0;
    outline: none;
    display: block;
    text-align: center;
    margin: 0;
  }
}

.el-popper[x-placement^=top] {
  box-shadow: 0px 0px 10px #888888;
  margin-left: 6px;
  margin-right: -25px;

  button {
    display: block;
  }

  .operation {
    border: 0;
    outline: none;
    display: block;
    text-align: center;
    margin: 0;
  }
}
</style>
